<template>
	<view class="content">
		<!-- 页面头部 -->
		<!-- <view class="setting-tittle-box" @click="back">
			<uni-icon class="arrow_right" type="arrowleft" size="30"></uni-icon>
			<text>设置</text>
		</view> -->
		<view class="main-content">
			<!-- 头像 -->
			<uni-password ref="secrity" @input="onInput" @confirm="onConfirms" v-if="pay_pass_display">
				请输入6位支付密码
			</uni-password>
			<view class="photo-box">
				<text class="photo">头像</text>
				<image :src="headImg" mode=""></image>
				<!-- <uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon> -->
			</view>
			<!-- 昵称 -->
			<view class="nickname-box">
				<text class="nickname">昵称</text>
				<text class="nickname_">{{userNmae}}</text>
			</view>
			<!-- 姓名 -->
			<view class="name-box">
				<text class="name">姓名</text>
				<text class="name_"> {{name}}</text>
				
			</view>
			<!-- ID Card -->
			<view class="ID-box">
				<text class="ID">身份证号码</text>
				<text>{{idcard}}</text>
				
			</view>
			<!-- 手机号 -->
			<view class="phone-box">
				<text class="phone">手机号</text>
				<text v-if="user_phone_id">{{user_phone_id}}</text>
				<!-- <uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon> -->
			</view>
			<!-- 修改个人信息 -->
			<view class="alter-box" @click="changeinformation">
				<text class="alter">修改个人信息</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- <view class="alter-box" @click="myMch" v-if="isMch">
				<text class="alter">我的店铺</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view> -->
			<!-- 推送消息设置 -->
			<!-- <view class="news-box">
				<text class="news">消息推送设置</text>
				<view class="btn-box">
					                <switch checked @change="PushSwitch" />

				</view>
			</view> -->
			<!-- 我的记录 -->
			<view class="record-box" @click="toTransactionDetail">
				<text class="record">我的记录</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- 已分享分数 -->
			<view class="share-box">
				<view class="share">
					<text class="share">已分享人数</text>
				</view>
				<view class="num">
					<text class="num">{{Sharenumber}}</text>
				</view>
				
			</view>
			<!-- 推荐给朋友 -->
			<view class="recommend-box" @click="toRecommend">
				<text class="recommend">推荐给朋友</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			
			<!-- 修改登录密码 -->
			<view class="alter-box" @click="alterPassword">
				<text class="alter">修改登录密码</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- <view class="alter-box" @click="fns.waiting()" v-if="pay_password">
				<text class="alter">修改支付密码</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<view class="alter-box" @click="pay_pass_display=true" v-else>
				<text class="alter">设置支付密码</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view> -->
			<view class="alter-box" @click="goGetcoedpassword" >
				<text class="alter">设置支付密码</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- 地址列表 -->
			<view class="alter-box" @click="goaddress" >
				<text class="alter">设置收货地址</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- 地址列表 -->
			<view class="alter-box" @click="helpCenter" >
				<text class="alter">帮助中心</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- 关于我们 -->
			<!-- #ifdef APP-PLUS -->
			<view class="about-me-box" @click="version_update">
				<text class="about">当前版本</text>
				<text> {{versionNumber}}</text>
				<uni-icon class="arrowRight" type="arrowright" size="30"></uni-icon>
			</view>
			<!-- #endif -->
			<view class="foot-box">
				<text class="about">绵阳优狐网络科技有限公司</text>
			</view>
		</view>
		<view class="log-out-box" @click="logOut">
			<text>退出登录</text>
		</view>
	</view>
</template>

<script>
	import uniPassword from '@/components/ku3gitxdx-payment-password/ku3gitxdx-payment-password.vue'
	import uniIcon from "@/components/uni-icon/uni-icon.vue"
	import eonfox from '@/components/eonfox/eonfox.js';
	import fns from '@/components/eonfox/fns.js';
	import pay from '@/components/eonfox/pay.js';
	var ef = new eonfox();
	export default {
		data() {
			return {
				userNmae :"",
				name:'',
				versionNumber:[],
				pphone:[],
				Sharenumber:'',
				idcard:'',
				imageID:'',
				pay_password:false,
				address:'',
				headImg:'../../static/user.png',
				isMch:false,
				pay_pass_display:false,
				user_phone_id:''
			};
		},
		onShow() {
			
			// #ifdef APP-PLUS
			this.versionNumber = plus.runtime.version;
			// #endif
			
			uni.showLoading({
				title:'正在加载'
			})
			let __this = this;
			ef.submit({
				request: { s: ['USERSELF'] ,
				 p :["USERPHONESELFVERIFY"],
				 phone:['USERPHONESELFVERIFY',[{user_phone_id:__this.pphone,user_phone_type:1}]],
				 sharenumber:['USERSELFSONCOUNT'],
				 sf:['USERIDENTITYSELF'],
				 config: ['APPLICATIONCONFIG'],
				  sj: ['MERCHANTSELF'],
				 },
				callback: function(data){
					uni.hideLoading();
					var userData=data.data
					console.log(userData);
					var dataList = fns.checkError(data,['s'], function(erron, error){
						
					});
					if(data.data.phone.data){
					 __this.pphone=((function(){try{ return data.data.phone.data;}catch(e){return false;}}()))
					__this.user_phone_id= __this.pphone[0].user_phone_id;
					 // __this.pphone[]=data.data.phone.data
					}
					
					//七牛云
					__this.address=data.data.config.data.qiniu_domain;
					__this.Sharenumber=data.data.sharenumber.data
					__this.idcard=data.data.sf.data.card_number
					console.log(__this.idcard)
					if( (function(){try{ return userData.s.data.user_nickname, true;}catch(e){return false;}}()) ){
						__this.userNmae =userData.s.data.user_nickname;
						__this.name=userData.s.data.user_compellation;
					}else if(userData.p.data[0]){
						
						__this.userNmae = (function(){try{ return userData.p.data[0].user_phone_id;}catch(e){return false;}}());
					}
					if(dataList.config&&dataList.config.app_android_version){
						__this.version=dataList.config.app_android_version
					}
					if(userData.s.data.user_nickname==""){
						__this.userNmae="未设置";
					}
					if(userData.s.data.user_compellation==""){
						__this.name="未实名";
					}
					//正式姓名
					if(dataList.sf.real_name){
						__this.name=dataList.sf.real_name;
					}
					//是否商家
					if(dataList.sj){
						__this.isMch=true;
					}
					
					//头像
					
					if(dataList.s.user_logo_image_id!=""){
						__this.imageID=dataList.s.user_logo_image_id;
						__this.headImg=__this.address+__this.imageID+'?imageView2/1/w/160';
						console.log('头像',__this.headImg);
					}else if(dataList.s.user_logo_image_id==""){
						__this.headImg='../../static/user.png'
					}
					
					
				},
				error: function(err) {
					console.log('出错啦', err);
					uni.showToast({
						title:'出错啦',
						icon:'none'
					})
				}
			});
		},
		components: {
			uniIcon,uniPassword
		},
		methods: {
			goGetcoedpassword(){
				uni.navigateTo({
					url:'../../pagesB/getcoedpassword/getcoedpassword'
				})
			},
			onInput(e) {
				//e.cancel = true;
				// console.log('onInput',e,e.cancel);
			},
			onConfirms(e) {
				var _this=this
				let password = e.value;
				console.log('password',password,password.length);
				var ef = new eonfox();
					ef.submit({
						request: {s: ['USERSELFPAYPASSWORD',[{password:password}]] },
						callback: function(data) {
							fns.checkError(data,'s',function(errno,error){
								uni.showToast({
									title:error,
									icon:'none'
								})
							})
							if(data.data.s.data){
								uni.showToast({
									title:'支付密码设置成功',
									icon:'none',
									success() {
										setTimeout(function(){
											uni.navigateTo({
												url:'../../pagesA/setting/setting'
											})
										},1000)
									}
								})
								
								
							}
							  console.log(data);
							
						},
						error: function(err) {
							
						}
					});
			},
			helpCenter(){
				uni.navigateTo({
					url:'../helpCenter/helpCenter'
				})
			},
			version_update(){
				
				// #ifdef APP-PLUS
				uni.showLoading({
					title:'正在检测更新',
					success() {
						ef.submit({
							request:{
								config: ['APPLICATIONCONFIG'],
							},
							callback(data){
								uni.hideLoading()
								var dataList = fns.checkError(data,'config',function(errno,error){
									uni.showToast({
										title:error,
										icon:'none'
									});
								})
								console.log('callback(index)',dataList);
								if( !dataList ){
									return false;
								}
								
								if(dataList.config && dataList.config.app_android_version &&dataList.config.app_android_version.number){
									 var Versionnumber = dataList.config.app_android_version.number
									 var info=dataList.config.app_android_version.info
									 var name=dataList.config.app_android_version.name
									 var download=dataList.config.app_android_version.download
								}
								if( Versionnumber != plus.runtime.version ){
									uni.showModal({
										title:'版本已更新',
										content:info+ name,
										cancelText:'取消更新',
										confirmText:'确认更新',
										success: function (res) {
											if (res.confirm) {
												setTimeout(function(){
													plus.runtime.openURL(download) 
												},2000)
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
										
									});
								}
								
							}
						})		
					}
				})
				// #endif
				
			},
			toRecommend() {
				uni.navigateTo({
					url: '../../pagesB/QRCode/QRCode'
				})
			},
			changeinformation() {
				uni.navigateTo({
					url: '../../pagesA/changeInformation/changeInformation'
				})
			},
			goaddress(){
				uni.navigateTo({
					url:'../address/address'
				})
			},
			websocket(){
				uni.navigateTo({
					url:'../websocket/websocket'
				})
			},
			myMch(){
// 				uni.navigateTo({
// 					url: '../../pagesA/transactionDetail/transactionDetail'
// 				})	
fns.err('敬请期待')
			},
			toTransactionDetail() {
				uni.navigateTo({
					url: '../../pagesA/transactionDetail/transactionDetail'
				})
			},
			alterPassword() {
				uni.navigateTo({
					url: '../../pagesA/forget-password/forget-password'
				})
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			logOut() {
				
				let ef = new eonfox();
				ef.submit({
					request: { s: ['USERLOGOUT'] },
					callback: function(data) {
						uni.clearStorage();
						// websocket.restart();
						uni.showToast({
							title: '退出成功',
							icon: 'success'
						});
						setTimeout(function(){
							uni.reLaunch({
								url:
									'../../pages/index/index'
							});
							// ereee
							
						},1000);
					},
					error: function(err) {
						uni.clearStorage();
						// websocket.restart();
						console.log('出错啦', err);
						uni.showToast({
							title:JSON.stringify(err),
							icon:'none'
						})
						uni.reLaunch({
							url:
								'../../pages/index/index'
						});
					}
				});
			}
		}
	}
</script>

<style scoped lang="stylus" ref="stylesheet/stylus">
	.content
		width 100%
		margin-top 10upx
		background-color #fff
		display flex
		justify-content center
		align-items center
		flex-direction column
		.setting-tittle-box
			width 95%
			height 55px
			display flex
			justify-content center
			align-items center
			.arrow_right
				flex 3
			text
				flex 4
				font-size 20px
		.main-content
			width 95%
			height 650px
			font-size 16px
			display flex
			justify-content center
			align-items center
			flex-direction column
			.photo-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				flex-direction row
				border-bottom 1px solid #ccc
				.photo
					flex 6
				image
					width 40px
					height 40px
					border-radius 50%
			.nickname-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				flex-direction row
				border-bottom 1px solid #ccc
				.nickname
					flex 6
			.name-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				flex-direction row
				border-bottom 1px solid #ccc
				.name
					flex 6
			.ID-box
				display flex
				justify-content center
				align-items center
				width 100%
				border-bottom 1px solid #ccc
				flex 1
				.ID
					flex 6
			.phone-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				border-bottom 1px solid #ccc
				.phone
					flex 6
			.news-box
				display flex
				justify-content center
				align-items center
				width 100%
				border-bottom 1px solid #ccc
				flex 1
				.news
					flex 6
			.record-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				border-bottom 1px solid #ccc
				position relative
				.record
					width 100%
					height 100%
					line-height 50px
					
				.arrowRight
					position absolute
					top 15px 
					right 0
			.share-box
				flex 1
				width 100%
				display flex
				line-height 50px
				justify-content center
				border-bottom 1px solid #ccc
				.share
					flex 9
				.num
					flex 2
					text-align right
					padding-right 15upx
			.recommend-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				border-bottom 1px solid #ccc
				position relative
				.recommend
					width 100%
					height 100%
					line-height 50px
					
				.arrowRight
					position absolute
					top 15px 
					right 0
			.alter-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				border-bottom 1px solid #ccc
				.alter
					flex 6
			.about-me-box
				flex 1
				width 100%
				display flex
				justify-content center
				align-items center
				border-bottom 1px solid #ccc
				.about
					flex 6
		.log-out-box
			width 100%
			height 60px
			font-size 14px
			color #E51C23
			margin-top 40px
			background-color #EEE8E8
			display flex
			justify-content center
			align-items center
</style>
<style>
	.foot-box{
		font-size: 10px;text-align: center;color: #666666;
		margin-top: 15px;
	}
</style>